import { ref } from 'vue'
import { cancelOrder } from '@/api/order'

const useCancelOrderForm = () => {
  const form = ref<{ remark: string; settlementStatus: 1 | 2 }>({
    remark: '',
    settlementStatus: 1,
  })

  const submitLoading = ref(false)
  const submit = async (orderIds: Array<string>) => {
    submitLoading.value = true
    const res = await cancelOrder({ ...form.value, workIds: orderIds })
    submitLoading.value = false
    return res.data as { code: number; data: object; message: string; success: boolean }
  }

  const reset = () => {
    form.value.remark = ''
    form.value.settlementStatus = 1
  }

  return {
    form,
    submitLoading,
    reset,
    submit,
  }
}

export default useCancelOrderForm
